package cn.woblog.recyclerviewsample;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.widget.LinearLayout;
import cn.woblog.recyclerviewsample.adapter.EnhanceAdapterWrapper;
import java.util.ArrayList;
import java.util.Random;

public class HeaderFooterActivity1 extends AppCompatActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_header_footer1);

    RecyclerView rv = (RecyclerView) findViewById(R.id.rv);
//    rv.setLayoutManager(new LinearLayoutManager(this));
//    rv.setLayoutManager(new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false));
//    rv.setLayoutManager(new GridLayoutManager(this, 2));
    rv.setLayoutManager(new StaggeredGridLayoutManager(2, LinearLayout.VERTICAL));

    HeaderFooterCustomAdapter useCustomAdapter = new HeaderFooterCustomAdapter(this);
    //添加头部，底部
    EnhanceAdapterWrapper enhanceAdapterWrapper = new EnhanceAdapterWrapper(useCustomAdapter);
    rv.setAdapter(enhanceAdapterWrapper);

//    rv.addItemDecoration(new DividerItemDecoration(this,LinearLayout.VERTICAL));
//    rv.addItemDecoration(new EnhanceDividerItemDecoration(this, LinearLayout.VERTICAL));
//    rv.addItemDecoration(new EnhanceDividerItemDecoration(this, LinearLayout.HORIZONTAL));

    enhanceAdapterWrapper.addHeaderView(getTextView());
    enhanceAdapterWrapper.addHeaderView(getTextView());

    enhanceAdapterWrapper.addFooterView(getTextView());
    enhanceAdapterWrapper.addFooterView(getTextView());

    Random random = new Random();

    ArrayList<Data> data = new ArrayList<>();
    for (int i = 0; i < 50; i++) {
      data.add(new Data("Item " + i, random.nextInt(50) + 200));
    }

    useCustomAdapter.setData(data);

  }

  private View getTextView() {
    View view = View.inflate(this, R.layout.header_1, null);
    return view;
  }

  public class Data {

    private String string;
    private int height;

    public Data(String string, int height) {
      this.string = string;
      this.height = height;
    }

    public String getString() {
      return string;
    }

    public void setString(String string) {
      this.string = string;
    }

    public int getHeight() {
      return height;
    }

    public void setHeight(int height) {
      this.height = height;
    }
  }
}
